/*
 * Copyright (c) 2017, www.zm0618.com All Rights Reserved..
 */

package com.light.hessian.provider.slot;

import com.light.hessian.provider.config.ProviderInfo;
import com.light.hessian.provider.config.ProviderStatus;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhaojun on 2017/02/15.
 */
public class ProviderStatusSlotHolder {

    private volatile List<ProviderStatusSlot>  statusSlots=new ArrayList<ProviderStatusSlot>();


    public void registerProvider(List<ProviderInfo> providerInfoList) {

        List<ProviderStatusSlot> statusSlots0 = new ArrayList<ProviderStatusSlot>(providerInfoList.size());
        if (CollectionUtils.isNotEmpty(providerInfoList)){
            for (ProviderInfo providerInfo:providerInfoList) {
                ProviderStatusSlot statusSlot=new ProviderStatusSlot();
                statusSlot.setProvider(providerInfo.getProvider());
                statusSlot.setBaseProviderInfo(providerInfo);
                statusSlot.setStatus(ProviderStatus.UP);
                statusSlot.setShowBalancer(providerInfo.isShowBalancer());
                statusSlots0.add(statusSlot);
            }
        }
        statusSlots=statusSlots0;
    }

    public List<ProviderStatusSlot> getProviderStatusSlots() {
        return statusSlots;
    }
}
